//
//  RanTool.h
//  shakalaka
//
//  Created by Ran on 15/8/18.
//  Copyright (c) 2015年 Justice. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "RBDefine.h"
#import "RBCellModel.h"

@interface NSMutableArray(RanAttributeString)

/**
 *  添加文字
 *  默认参数: font: [UIFont systemFontOfSize: 15]; color: [UIColor blackColor]; string: @""
 */
- (void)addAttributeStringWithFont: (UIFont *)font color: (UIColor *)color string: (NSString *)string;
/**
 *  添加文字
 *  lineSpacing: 行距
 *  !!!!!单行中文设置spacing会多余一个spacing,
 *  !!!!!比较复杂的排版,还是建议用YYText(NSMutableAttributedString+RBAdd)
 */
- (void)addAttributeStringWithFont: (UIFont *)font color: (UIColor *)color string: (NSString *)string lineSpacing: (CGFloat)spacing;

- (void)addAttributeStringWithFont: (UIFont *)font color: (UIColor *)color string: (NSString *)string lineSpacing: (CGFloat)spacing underLineHeight: (CGFloat)underLineHeight underLineColor: (UIColor *)underLineColor;

- (void)addAttributeStringWithFont: (UIFont *)font color: (UIColor *)color string: (NSString *)string lineSpacing: (CGFloat)spacing througnLineHeight: (CGFloat)througnLineHeight throughLineColor: (UIColor *)throughLineColor;


/**
 *  添加图片
 *  手动校正位置
 */
- (void)addAttributeStringWithImage: (UIImage *)image imageFrame: (CGRect)framez;
/**
 *  添加图片
 *  maxFont:辅助校正位置,纵向居中
 */
- (void)addAttributeStringWithImage: (UIImage *)image imageSize: (CGSize)imageSize maxFont: (UIFont *)maxFont;

@end

@interface RanTool : NSObject

/**
 *  快捷生成attributeString的方法
 *  示例:
 *  label.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
 *  [maker addAttributeStringWithFont:[UIFont systemFontOfSize:20] color:[UIColor redColor] string:@"red"];
 *  [maker addAttributeStringWithFont:nil color:[UIColor greenColor] string:@"green"];
 *  [maker addAttributeStringWithFont:nil color:nil string:@"black"];
 *   }];
 */
+ (NSAttributedString *)attributeStringMaker: (void(^)(NSMutableArray *maker))block;

/** 正则 */
+ (BOOL)regWithRegString: (NSString *)regString string: (NSString *)string;

/** 辅助判断手机号 */
+ (NSString *)fillNumString: (NSString *)numString;

/** 保证字符串非nil */
+ (NSString *)notNilString: (NSString *)string;

+ (CGSize)sizeWithAttText: (NSAttributedString *)text;
+ (CGSize)sizeWithAttText: (NSAttributedString *)text consSize: (CGSize)size;

+ (CGSize)sizeWithText:(NSString *)text consSize:(CGSize)size font:(UIFont *)font;

+ (UIEdgeInsets)safeEdge;
+ (CGFloat)safeBottomHeight;


/**
 weight:
 0 普通
 1 中
 2 粗
 */
+ (UILabel *)labelWithFontSize: (CGFloat)fontSize weight:(NSInteger)weight color: (id)color align:(NSTextAlignment)align text: (NSString *)text;
+ (UILabel *)labelWithFontSize: (CGFloat)fontSize weight:(NSInteger)weight color: (id)color align:(NSTextAlignment)align text: (NSString *)text bgColor: (id)bgColor radius: (CGFloat)radiuc;
+ (UILabel *)labelWithFontSize: (CGFloat)fontSize weight:(NSInteger)weight color: (id)color align:(NSTextAlignment)align text: (NSString *)text bgColor: (id)bgColor radius: (CGFloat)radius borderWidth: (CGFloat)borderWidth borderColor: (id)borderColor lines: (NSInteger)lines linePadding: (CGFloat)linePadding hPriority: (NSInteger)hPriority;

/**
 mode:
 0:fill
 1:aspectFit
 2:aspectFill
 */
+ (UIImageView *)imgViewWithMode:(NSInteger)mode radius: (CGFloat)radius imgName: (NSString *)imgName;

/**只支持NSString和NSDecimalNumber*/
+ (NSString *)num: (id)num plusNum: (id)plusNum;
/**只支持NSString和NSDecimalNumber*/
+ (NSString *)num: (id)num multiNum: (id)num1;

/** [3]天[01]时[01]分[01]秒 */
+ (NSArray *)dayHourMinuteSecondFromInterval:(NSInteger)interval;
/** [10].[50] */
+ (NSArray *)priceFromPrice: (NSString *)price;
+ (UIFont *)numFontWithSize: (CGFloat)size;

@end

@interface RanTool(RBImage)

/**
如果图片宽度大于maxWidth,等比缩放
 */
+ (UIImage *)image: (UIImage *)image withMaxWidth: (CGFloat)maxWidth;

/**
 按照compressionQuality压缩图片
 */
+ (NSData *)dataFromImage: (UIImage *)image
       compressionQuality: (CGFloat)compressionQuality;

/**
 工程默认压缩
 maxWidth:750
 compressionQuality:0.7
 */
+ (NSData *)dataFromImage: (UIImage *)image;
+ (NSArray *)dataArrayFromImageArray: (NSArray *)imageArray;

/**
 SDWebImage缓存图片
 */
+ (void)cacheImage: (UIImage *)image withUrl: (NSString *)url;

/**
 清除图片硬盘缓存
 */
+ (void)clearImageDiskCacheCompletion: (void(^)(void))completion;

/**
 存图片到相册
 */
+ (void)saveImageToAlbum: (UIImage *)image completion: (void(^)(BOOL suc, NSError *error))completion;

/**
 下载图片
 */
+ (void)downloadImage: (NSString *)imgUrl completion: (void(^)(UIImage *image))completion;

@end

@interface RanTool(Cell)

+ (RBCellModel *)cellModelWithSection: (NSInteger)section row: (NSInteger)row dataSource: (NSArray *)dataSource;
+ (RBCellModel *)cellModelWithType:(NSInteger)type dataSource: (NSArray *)dataSource;
+ (id)modelWithSection: (NSInteger)section row: (NSInteger)row dataSource: (NSArray *)dataSource;
+ (NSMutableArray *)cellModelsWithSection: (NSInteger)section dataSource: (NSArray *)dataSource;
+ (NSMutableArray *)modelsWithSection: (NSInteger)section dataSource: (NSArray *)dataSource;

+ (void)addCellModels: (NSArray *)cellModels withSection: (NSInteger)section dataSource: (NSArray *)dataSource;

+ (void)removeModelAtSection: (NSInteger)section row: (NSInteger)row dataSource: (NSArray *)dataSource;
+ (void)removeModel: (id)model dataSource: (NSArray *)dataSource;

+ (NSIndexPath *)indexPathWithModel: (id)model dataSource: (NSArray *)dataSource;

@end


@interface RanTool(Authority)

@end

@interface RanTool(System)

/** 系统分享 */
+ (void)systemShareWithText: (NSString *)text
                       image: (UIImage *)image
                         url: (NSString *)url
                  completion: (UIActivityViewControllerCompletionWithItemsHandler)completion;

/** 复制到剪切板 */
+ (void)pasteWithText: (NSString *)text;

/** 用safari打开网址 */
+ (void)openSafariWithUrl: (NSString *)url;

/** 发短信 */
+ (void)smsWithNumber: (NSString *)number;

/** 打电话 */
+ (void)telWithNumber: (NSString *)number;

/** 获取store版本 */
+ (void)getStoreVersionWithAppId: (NSString *)appId
                              cn: (BOOL)cn
                      completion: (void(^)(NSString *version, NSString *updateInfo, NSError *error))completion;

/** 打开store */
+ (void)openStoreWithAppId: (NSString *)appId;

#define kRBAppleID @"1457161659"

+ (void)updateTTC;
/** hudSuperView:传nil不显示hud */
+ (void)updateVersionWithHudSuperView:(UIView *)hudSuperView;

@end

@interface RanTool(ScrollView)

+ (void)adjustScrollView:(UIScrollView *)scrollView;

@end
